<template>
  <div class=" box" :style="{ backgroundImage: `url(https://s1.ax1x.com/2022/11/14/zAEa9A.png)` }">
    <div class="box-left">
      <div class="box-left-card">
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.localConfirmH5 }}</div>
          <div>{{ store.chinaTotal.localConfirm }}</div>
          <div>本土现有确诊</div>
        </section>
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.nowConfirm }}</div>
          <div>{{ store.chinaTotal.nowConfirm }}</div>
          <div>现有确诊</div>
        </section>
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.confirm }}</div>
          <div>{{ store.chinaTotal.confirm }}</div>
          <div>累计确诊</div>
        </section>
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.noInfect }}</div>
          <div>{{ store.chinaTotal.noInfect }}</div>
          <div>无症状感染者</div>
        </section>
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.importedCase }}</div>
          <div>{{ store.chinaTotal.importedCase }}</div>
          <div>境外输入</div>
        </section>
        <section style="color: white">
          <div>较上日+{{ store.chinaAdd.dead }}</div>
          <div>{{ store.chinaTotal.dead }}</div>
          <div>累计死亡</div>
        </section>
      </div>
      <div class="box-left-pie"> </div>
      <div class="box-left-line"></div>
    </div>
    <div id="china" class="box-center">
    </div>
    <div style="color:white" class="box-right">

      <table class="table" cellspacing="0" border="1">
        <thead>
          <tr>
            <th>地区</th>
            <th>新增确诊</th>
            <th>累计确诊</th>
            <th>治愈</th>
            <th>死亡</th>
          </tr>
        </thead>
        <transition-group enter-active-class="animate__animated animate__flipInY " tag="tbody">
          <tr :key="Math.random() * 1000" v-for="item in store.yqItem">
            <td align="center">{{ item.name }}</td>
            <td align="center">{{ item.today.confirm }}</td>
            <td align="center">{{ item.total.confirm }}</td>
            <td align="center">{{ item.total.heal }}</td>
            <td align="center">{{ item.total.dead }}</td>
          </tr>
        </transition-group>

      </table>
      <button class="btn" @click="jumpHome">
        进入vue3学习世界
      </button>
    </div>
  </div>
</template>
<script setup lang='ts'>
import { useRouter, RouteRecordName } from 'vue-router'
import bg from '@/assets/bjtp.jpg'
import { useTestStore } from '../../store'
import { onMounted } from 'vue';
import * as echarts from 'echarts' //echars5系列需要改名引入 4不需要
import '@/assets/china'
import { geoCoordMap } from '../../assets/geoMap';
import axios from 'axios';
const router = useRouter()
const store = useTestStore()
onMounted(async () => {
  await store.getList()
  initCharts()
  initPie()
  initLine()
})
const initLine = () => {
  const charts = echarts.init(document.querySelector('.box-left-line') as HTMLElement)
  charts.setOption({
    backgroundColor: '#223651',
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: store.cityDetail.map(v => v.city),
      axisLine: {
        lineStyle: {
          color: '#fff'
        }
      }
    },
    yAxis: {
      type: 'value',
      axisLine: {
        lineStyle: {
          color: '#fff'
        }
      }
    },
    label: {
      show: true
    },
    series: [
      {
        data: store.cityDetail.map(v => v.local_confirm_add),
        type: 'line',
        smooth: true
      }
    ]
  })
}

const initPie = () => {
  const charts = echarts.init(document.querySelector('.box-left-pie') as HTMLElement)
  charts.setOption({
    backgroundColor: '#223651',
    tooltip: {
      trigger: 'item'
    },

    series: [
      {
        type: 'pie',
        radius: ['40%', '70%'],
        itemStyle: {
          borderRadius: 4,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: true,
        },
        emphasis: {
          label: {
            show: true,
            fontSize: '15',
          }
        },
        labelLine: {
          show: true
        },
        data: store.cityDetail.map(v => {
          return {
            name: v.city,
            value: v.local_confirm_add
          }
        })
      }
    ]
  })


}

const initCharts = () => {

  const city = store.list.diseaseh5Shelf.areaTree[0].children
  store.yqItem = city.filter(v => v.name === '山东')[0].children

  const data = city.map(v => {
    return {
      name: v.name,
      value: geoCoordMap[v.name].concat(v.total.nowConfirm),
      children: v.children
    }
  })

  const charts = echarts.init(document.querySelector('#china') as HTMLElement)

  charts.setOption({
    geo: {
      map: "china",
      aspectScale: 0.8,
      layoutCenter: ["50%", "50%"],
      layoutSize: "120%",
      itemStyle: {
        // normal: {
        areaColor: {
          type: "linear-gradient",
          x: 0,
          y: 1200,
          x2: 1000,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: "#152E6E", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#0673AD", // 50% 处的颜色
            },
          ],
          global: true, // 缺省为 false
        },
        shadowColor: "#0f5d9d",
        shadowOffsetX: 0,
        shadowOffsetY: 15,
        opacity: 0.5,
        //},

      },
      emphasis: {
        areaColor: "#0f5d9d",
      },

      regions: [
        {
          name: "南海诸岛",
          itemStyle: {
            areaColor: "rgba(0, 10, 52, 1)",
            borderColor: "rgba(0, 10, 52, 1)",
            // normal: {
            opacity: 0,
            label: {
              show: false,
              color: "#009cc9",
            },
            // },
          },
          label: {
            show: false,
            color: "#FFFFFF",
            fontSize: 12,
          },
        },
      ],
    },
    series: [
      {
        type: "map",
        // selectedMode: "multiple",
        map: "china",
        aspectScale: 0.8,
        layoutCenter: ["50%", "50%"], //地图位置
        layoutSize: "120%",
        zoom: 1, //当前视角的缩放比例
        // roam: true, //是否开启平游或缩放
        scaleLimit: {
          //滚轮缩放的极限控制
          min: 1,
          max: 2,
        },
        label: {
          show: true,
          color: "#FFFFFF",
          fontSize: 12,
        },
        itemStyle: {
          //normal: {
          areaColor: "#0c3653",
          borderColor: "#1cccff",
          borderWidth: 1.8,
          // },

        },
        emphasis: {
          areaColor: "#56b1da",
          label: {
            show: true,
            color: "#fff",
          },
        },
        data: data,
      },
      {
        name: 'Top 5',
        type: 'scatter',
        coordinateSystem: 'geo',
        //   symbol: 'image://http://ssq168.shupf.cn/data/biaoji.png',
        // symbolSize: [30,120],
        // symbolOffset:[0, '-40%'] ,
        symbol: 'pin',
        symbolSize: [80, 80],

        label: {
          //normal: {
          show: true,
          formatter(v: any) {

            return v.value[2]
          }
          // }
        },
        itemStyle: {
          // normal: {
          color(v: any) {
            if (v.value[2] <= 20) {
              return 'green'
            } else if (v.value[2] <= 200) {
              return 'yellow'
            } else if (v.value[2] > 200) {
              return 'red'
            }
          }, //标志颜色


          //  }
        },
        data: data,

      },
    ],
  }
  )
  charts.on('click', (v: any) => {
    store.yqItem = v.data.children
  })

}

const jumpHome = () => {
  router.push({
    name: 'index',

  })
}

</script>
<style scoped lang='less'>
@itemColor: #41b0db;
@itemBg: #223651;
@itemBorder: #212028;


.table {
  width: 100%;
  background: #212028;

  tr {
    th {
      padding: 5px;
      white-space: nowrap
    }

    td {
      padding: 5px 10px;
      width: 100px;
      white-space: nowrap;
    }

  }

}

.box {
  height: 100%;
  display: flex;
  background-repeat: round;

  &-left {
    width: 400px;
    display: flex;
    flex-direction: column;

    &-line {
      flex: 1;
      margin-top: 10px;
    }

    &-pie {
      flex: 1;
      margin-top: 10px;
    }

    &-card {
      flex: 1;
      display: grid;
      grid-template-columns: auto auto auto;
      grid-template-rows: auto auto;

      section {
        background-color: @itemBg ;
        border: 1px solid @itemBorder;
        display: flex;
        flex-direction: column;
        align-items: center;

        div:nth-child(2) {
          color: @itemColor;
          padding: 10px 0;
          font-size: 20px;
        }
      }

    }
  }

  &-center {
    flex: 1;
  }

  &-right {
    width: 400px;
    display: flex;
    flex-direction: column;

    .btn {
      margin: 20px auto;
      width: 200px;
      height: 100px;
      background-color: @itemBg;
      color: white;
    }
  }
}
</style>
